package com.hemaapp.yjnh.bean;

import java.io.Serializable;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.uu.utils.uuUtils;

import xtom.frame.XtomObject;
import xtom.frame.exception.DataParseException;

/**
 * 购物车
 */
public class Cart extends XtomObject implements Serializable {

	private static final long serialVersionUID = 1L;

	private String seller_id;// 卖家id
	private String seller_name;// 卖家名称
	private String total_fee;// 购物车内所有商品总价(不含运费)
	private boolean isCheck = false;
	
	private ArrayList<ChildItem> childs = new ArrayList<Cart.ChildItem>();

	public Cart(JSONObject jsonObject) throws DataParseException {
		if (jsonObject != null) {
			try {
				seller_name = get(jsonObject, "seller_name");
				seller_id = get(jsonObject, "seller_id");
                total_fee = get(jsonObject, "total_fee");
				if (!jsonObject.isNull("childItems")
						&& !isNull(jsonObject.getString("childItems"))) {
					JSONArray jsons = jsonObject.getJSONArray("childItems");
					for (int i = 0; i < jsons.length(); i++) {
						JSONObject child = jsons.getJSONObject(i);
						ChildItem item = new ChildItem(child);
						item.setSeller_id(seller_id);
						item.setSeller_name(seller_name);
						childs.add(item);
					}
				}

				log_i(toString());
			} catch (JSONException e) {
				throw new DataParseException(e);
			}
		}
	}

	public String getseller_id() {
		return seller_id;
	}

	public String getseller_name() {
		return seller_name;
	}

	public String gettotal_fee() {
		return total_fee;
	}
    
    public boolean getChecked() {
        return isCheck;
    }
    
    public void setChecked(boolean checked) {
        this.isCheck = checked;
    }
	
	public ArrayList<ChildItem> getChildItems() {
	    return childs;
	}
	
	public class ChildItem  extends XtomObject implements Serializable {
	    
	    private static final long serialVersionUID = 1L;
	    
	    private String id;// 购物车记录主键id   特别注意：订单号等同于记录主键id
	    private String client_id;// 用户id     
	    private String keyid;// 商品id    比如blog_id
	    private String name;// 商品名称
		private String specid;//规格id
		private String one_spec;// 一级规格名称
		private String two_spec;// 二级规格名称
		private String one_specname;// 一级规格内容
		private String two_specname;// 二级规格内容
		private String expressfee;// 运费
	    private String imgurl;// 商品图片     
	    private String imgurlbig;// 商品大图片    
	    private String price;// 单价  
	    private String unit;// 单位
	    private String buycount;// 购买数量    
	    private String subtotal;// 总价  
	    private String score;// 粮票价 1
	    private String regdate;// 加入日期
	    private String enddate;// 过期日期	30分钟过期
		private String seller_id;// 卖家id
		private String seller_name;// 卖家名称
	    private boolean isChecked = false;
        private boolean isSellerChecked = false;//整个商家是否全选
	    
	    public ChildItem(JSONObject jsonObject) throws DataParseException {
	        if (jsonObject != null) {
	            try {
	                id = get(jsonObject, "id");
	                client_id = get(jsonObject, "client_id");
	                keyid = get(jsonObject, "keyid");
	                name = get(jsonObject, "name");
	                imgurl = get(jsonObject, "imgurl");
	                imgurlbig = get(jsonObject, "imgurlbig");
	                price = uuUtils.formatAfterDot2(get(jsonObject, "price"));
	                unit = get(jsonObject, "unit");
	                buycount = get(jsonObject, "buycount");
	                subtotal = uuUtils.formatAfterDot2(get(jsonObject, "subtotal"));
	                regdate = get(jsonObject, "regdate");
	        	    expressfee = get(jsonObject, "expressfee");
	        	    enddate = get(jsonObject, "enddate");
	                score = uuUtils.formatAfterDot2(get(jsonObject, "score"));
					specid = get(jsonObject, "specid");
					one_spec = get(jsonObject, "one_spec");
					two_spec = get(jsonObject, "two_spec");
					one_specname = get(jsonObject, "one_specname");
					two_specname = get(jsonObject, "two_specname");

					log_i(toString());
	            } catch (JSONException e) {
	                throw new DataParseException(e);
	            }
	        }
	    }

		public String getId() {
			return id;
		}

		public String getClient_id() {
			return client_id;
		}

		public String getKeyid() {
			return keyid;
		}

		public String getName() {
			return name;
		}

		public String getExpressfee() {
			return expressfee;
		}

		public String getImgurl() {
			return imgurl;
		}

		public String getImgurlbig() {
			return imgurlbig;
		}

		public String getPrice() {
			return price;
		}

		public String getUnit() {
			return unit;
		}

		public String getBuycount() {
			return buycount;
		}

		public String getSubtotal() {
			return subtotal;
		}

		public String getRegdate() {
			return regdate;
		}

		public String getEnddate() {
			return enddate;
		}
		
		public String getScore() {
			return score;
		}

		public boolean isChecked() {
			return isChecked;
		}

		public void setBuycount(String buycount) {
			this.buycount = buycount;
		}

		public void setChecked(boolean isChecked) {
			this.isChecked = isChecked;
		}

		public void setSeller_id(String seller_id) {
			this.seller_id = seller_id;
		}

		public void setSeller_name(String seller_name) {
			this.seller_name = seller_name;
		}

        public String getSeller_id() {
            return seller_id;
        }

        public String getSeller_name() {
            return seller_name;
        }

        public void setSellerChecked(boolean sellerChecked) {
            isSellerChecked = sellerChecked;
        }

        public boolean isSellerChecked() {
            return isSellerChecked;
        }

		public String getOne_spec() {
			return one_spec;
		}

		public String getTwo_spec() {
			return two_spec;
		}

		public String getOne_specname() {
			return one_specname;
		}

		public String getTwo_specname() {
			return two_specname;
		}

        public String getSpecid() {
            return specid;
        }
    }
}
